
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:Initialize()
	self.exploded = false
	self.ticking = true
	self.flightvector = self.Entity:GetUp() * 50
	self.Entity:SetModel( "models/props_junk/PopCan01a.mdl" ) 	
	self.Entity:PhysicsInit( SOLID_VPHYSICS )      -- Make us work with physics,  	
	self.Entity:SetMoveType( MOVETYPE_NONE )   --after all, gmod is a physics  	
	self.Entity:SetSolid( SOLID_VPHYSICS )        -- CHEESECAKE!    >:3            
	self.DieTime = CurTime() + 15
	self:Think()
	
end   

function ENT:Think()
	local trace = {}
		trace.start = self.Entity:GetPos()
		trace.endpos = self.Entity:GetPos() + self.flightvector *3
		trace.filter = self.Entity 
	local tr = util.TraceLine( trace )
	
	if (tr.Hit) then
		if ( self.exploded == false ) then
			if ( self.exploded == false && self.ticking == true ) then
				util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 100, 50)
				if (tr.Entity:IsWorld() || tr.Entity:IsPlayer() || tr.Entity:IsNPC() || tr.HitSky) then
					self.exploded = true
					self.Entity:Remove()
					return true
				end
			if (tr.Entity:IsValid()) then
				
					cbt_dealhcghit( tr.Entity, self.cannon.power, 7, tr.HitPos , tr.HitPos)
			end

				self.exploded = true
				self.Entity:Remove()
			end
		end
	end
	if CurTime() > self.DieTime then
		self.Entity:Remove()
	end
	self.Entity:SetPos(self.Entity:GetPos() + self.flightvector)
	self.Entity:NextThink( CurTime() )
	return true
	end
 
 
